<?php
class News_model extends MY_Model
{
    public function getNewsType($new_type_id)
    {
        $sql = "SELECT *
                FROM news 
                WHERE active = 1 
                AND new_types_id = $new_type_id
                ORDER BY id DESC";
        $query = $this->db->query($sql);

        $data = array();
        if ($query->num_rows() > 0)
        {
           foreach ($query->result_array() as $row)
           {
                $data[] = $row;    
           }
           return $data;;
        }
        
        return false;
    }
    
    public function getExpertNews($new_type_id, $news_id)
    {        
        $id = "";
        if($news_id > 0)
        {
            $id = "AND id = $news_id";
        }                                     
        
        $sql = "SELECT *
                FROM news 
                WHERE active = 1 
                AND new_types_id = $new_type_id
                $id
                ORDER BY id DESC
                LIMIT 1";
                
        //echo $sql;
                
        $query = $this->db->query($sql);

        $data = array();
        if ($query->num_rows() > 0)
        {
           $row = $query->row_array();
           return $row;
        }                                                      
        
        return false;
    }
    
    public function getOtherExpertNews($new_type_id, $news_id = 0)
    {       
        $id  = "";
        if($news_id > 0)
        {
            $id = " AND id != $news_id";
        }
        
        $sql = "SELECT *
                FROM news 
                WHERE active = 1 
                AND new_types_id = $new_type_id
                $id
                ORDER BY id DESC";
                
        /*echo "<br/>";
        echo $sql;   */
        
        $query = $this->db->query($sql);

        $data = array();
        if ($query->num_rows() > 0)
        {
           foreach ($query->result_array() as $row)
           {
                $data[] = $row;    
           }
           return $data;;
        }                                                      
        
        return false;
    }
}
?>
